//
//  ZLDetailCollectionViewCell.m
//  TripTogether
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 杨泓晔. All rights reserved.
//

#import "ZLDetailCollectionViewCell.h"
#import "StarView.h"

@interface ZLDetailCollectionViewCell ()

@property (nonatomic, strong)UIImageView *myImageView;
@property (nonatomic, strong)UILabel *nameLabel;

@property (nonatomic, strong)StarView *starView;

@property (nonatomic, retain) UILabel *rating_users;


@end

@implementation ZLDetailCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        
        self.myImageView = [[UIImageView alloc]init];
        
//        self.myImageView.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:self.myImageView];
        [self.myImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.top.equalTo(self.contentView);
            make.width.mas_equalTo((SCREEN_WIDTH - 27 * AUTO_WIDTH)/2);
            make.height.mas_equalTo((SCREEN_WIDTH - 25 * AUTO_WIDTH)/2);
        }];
        self.myImageView.layer.masksToBounds = YES;
        self.myImageView.layer.cornerRadius = 8 * AUTO_WIDTH;
        
        self.nameLabel = [UILabel new];
//        self.nameLabel.textAlignment = NSTextAlignmentCenter;
        self.nameLabel.textColor = [UIColor whiteColor];
        [self.myImageView addSubview:self.nameLabel];
        self.nameLabel.font = [UIFont fontWithName:@"Gurmukhi MN" size:18.0f];
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.equalTo(self.myImageView.mas_left).offset(10);
            make.right.equalTo(self.myImageView.mas_right).offset(-40*AUTO_WIDTH);
            make.bottom.equalTo(self.myImageView.mas_bottom).offset(-20* AUTO_HEIGHT);
            make.height.equalTo(@(40 * AUTO_HEIGHT));
        }];
        
        self.starView = [[StarView alloc]initWithFrame:CGRectMake(10, self.frame.size.height - 20, self.frame.size.width/2, 10) number:5];
        [self.myImageView addSubview:self.starView];
        [self.starView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.equalTo(self.nameLabel);
            make.right.equalTo(self.myImageView.mas_right).offset(-85*AUTO_WIDTH);
            make.top.equalTo(self.nameLabel.mas_bottom);
            make.height.equalTo(@(10* AUTO_HEIGHT));
            
        }];
        
        self.rating_users = [UILabel new];
        [self.myImageView addSubview:self.rating_users];
        self.rating_users.font = [UIFont systemFontOfSize:11.0f];
        self.rating_users.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
        [self.rating_users mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.equalTo(self.myImageView.mas_right).offset(-75*AUTO_WIDTH);
            make.right.equalTo(self.myImageView.mas_right);
            make.top.equalTo(self.nameLabel.mas_bottom);
            make.height.equalTo(@(10* AUTO_HEIGHT));
            
        }];
        
        
    }
    return self;
}

- (void)setZlDetailImageM:(ZLDetailImageModel *)zlDetailImageM
{
    [self.myImageView sd_setImageWithURL:[NSURL URLWithString:zlDetailImageM.cover] placeholderImage:PICHOLDEER];
    self.nameLabel.text = zlDetailImageM.name;
    
    [self.starView setStarWithNumber:zlDetailImageM.rating];
    
    if (zlDetailImageM.rating_users == 0) {
        self.rating_users.text = @"暂无点评";
    }else{
        self.rating_users.text = [NSString stringWithFormat:@"%ld点评",zlDetailImageM.rating_users];
    }
}



@end
